<template>
  <!-- 归档任务管理 -->
  <div class="archivingManag">
    <!-- <div class="seach-content">
      <div class="demo-input-suffix">
        任务分类：
        <el-cascader v-model="value" :props="props"></el-cascader>
        <el-button type="primary" @click="search()"
          ><i class="el-icon-zoom-in el-icon--left"> 搜索</i></el-button
        >
        <el-button @click="reset()"
          ><i class="el-icon-refresh el-icon--left"> 重置</i></el-button
        >
      </div>
    </div> -->
    <div class="btn-continer">
      <!-- <el-button type="success" class="btn-lvse" @click="submit"
        ><i class="el-icon-success el-icon--left"> 通过</i></el-button
      >
      <el-button type="danger" class="btn-hongse" @click="goBack"
        ><i class="el-icon-arrow-right el-icon--left"> 退回</i></el-button
      > -->
      <!-- <el-button><i class="el-icon-refresh el-icon--left"> 撤销</i></el-button> -->

      <div class="btn-right">
        <el-button
          icon="el-icon-refresh-right"
          style="margin-bottom: 10px"
          circle
          @click="refresh()"
        ></el-button>
      </div>
    </div>
    <div class="table-continer">
      <el-table
        :data="tableData"
        v-loading="loading"
        @selection-change="selectionchange"
        :header-cell-style="{ background: '#F0F0F6', color: '#2D3548' }"
        style="width: 100%"
      >
        <el-table-column type="selection" width="50"> </el-table-column>
        <el-table-column fixed prop="fileName" label="文件名称">
        </el-table-column>
        <el-table-column label="文件类型">
          <template slot-scope="scope">
            <span v-if="scope.row.fileType == 1">图片</span>
            <span v-if="scope.row.fileType == 2">视频</span>
            <span v-if="scope.row.fileType == 3">文档</span>
            <span v-if="scope.row.fileType == 4">音频</span>
          </template>
        </el-table-column>
        <el-table-column prop="creator" label="采集人"> </el-table-column>
        <el-table-column prop="fileTime" label="文档形成时间">
        </el-table-column>
        <el-table-column label="状态">
          <template slot-scope="scope">
            <span v-if="scope.row.fileStatus == 1">待提交</span>
            <span v-if="scope.row.fileStatus == 2">待审核</span>
            <span v-if="scope.row.fileStatus == 3">退回</span>
            <span v-if="scope.row.fileStatus == 4">审核通过</span>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button @click="goEdit(scope.row)" type="text" size="small"
              ><i class="el-icon-edit el-icon--left"> 编辑</i></el-button
            >
            <el-button type="text" size="small" @click="checkView(scope.row)"
              ><i class="el-icon-view el-icon--left"> 预览</i></el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="Pagination">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        background
        :current-page="currentPage"
        :page-sizes="[5, 10, 15]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalSize"
      >
      </el-pagination>
    </div>
    <checkimg
      :imgList="imgList"
      :showViewer="showViewer"
      @closeImg="closeImg"
    />
    <openPdf ref="Pdf" />
    <openMusci
      :showPlayer="showPlayer"
      :videoPlay="videoPlay"
      @musicClose="musicClose"
    />
    <el-dialog
      title="视频"
      :visible.sync="playVideo"
      width="40%"
      @close="closeMp4"
    >
      <div class="content">
        <openMp4 :video="video" :playVideo="playVideo" />
      </div>
    </el-dialog>
  </div>
</template>

<script>
import checkimg from "../components/checkImg.vue";
import openPdf from "../components/openPdf.vue";
import openMp4 from "../components/openMp4.vue";
import openMusci from "../components/openMusci.vue";

export default {
  name: "archivingManag",
  components: { checkimg, openPdf, openMp4, openMusci },
  data(vm) {
    return {
      showPlayer: false,
      playVideo: false,
      value: "",
      videoPlay: {
        title: "名称",
        artist: "音频",
        src: "",
        pic: "https://moeplayer.b0.upaiyun.com/aplayer/secretbase.jpg",
      },
      video: {
        // 视频播放源
        url: "",
        // 视频海报
        // cover: 'https://i.loli.net/2019/06/06/5cf8c5d9c57b510947.png',
        muted: false, // 是否静音播放
        loop: false, // 视频是否循环播放
        preload: "auto", // 视频预加载
        poster: "", // 原生视频默认海报暂不设置
        volume: 1, // 默认音量
        autoplay: false, // 视频自动播放
      },
      fileList: [
        {
          id: 1,
          fileName: "测试PDF",
          fileUrl: "http://192.168.3.189/aaa.pdf",
        },
      ],
      url: "http://192.168.3.189/aaa.pdf", //文件地址.
      accept: "",
      showViewer: false,
      imgList: [],
      seachValue: "",
      currentPage: 1,
      loading: false,
      tableData: [],
      targetData: [], //标签数组
      pageSize: 10,
      totalSize: 0,
      selectId: [],
      props: {
        lazy: true,
        lazyLoad(node, resolve) {
          setTimeout(async () => {
            const data = await vm._self.getTarget(node.value ? node.value : 0);
            const nodes = data.map((item) => ({
              value: item.id,
              label: item.name,
              leaf: node.level == 2 ? true : false,
            }));
            // 通过调用resolve将子节点数据返回，通知组件数据加载完成
            resolve(nodes);
          }, 100);
        },
      },
    };
  },
  mounted() {
    this.getList();
    // this.getTarget()
  },
  methods: {
    async getTarget(id) {
      let _that = this;
      return new Promise(function (resolve, reject) {
        _that.$api
          .getAllTarget({
            parentId: id,
          })
          .then((res) => {
            // console.log(res.data,'11')
            resolve(res.data);
          });
      });
    },
    getList() {
      this.loading = true;
      let obj = {
        pageNum: this.currentPage,
        pageSize: this.pageSize,
        fileName: "",
      };
      this.$api
        .getArchiveTaskByName(obj)
        .then((res) => {
          if (res.code == 200) {
            this.tableData = res.data.content;
            this.totalSize = res.data.totalSize;
          } else {
            this.tableData = [];
            this.totalSize = 0;
          }
          this.loading = false;
        })
        .catch(() => {
          this.tableData = [];
          this.totalSize = 0;
          this.loading = false;
        });
    },

    closeImg(flag) {
      this.showViewer = flag;
    },
      checkView(row) {
      this.$api.getUrl({ id: row.id }).then((res) => {
        let type = row.fileType;
        if (type == 1) {
          this.imgList = [CONFIG.url + "/" + res.data];
          this.showViewer = true;
        } else if (type == 3) {
          this.$refs.Pdf.previewFn(CONFIG.url + "/" + res.data);
        } else if (type == 2) {
          this.video.url = CONFIG.url + "/" + res.data;
          this.$nextTick(() => {
            this.playVideo = true;
          });
        } else {
          this.showPlayer = false;
          let ipUrl = CONFIG.url + "/" + res.data;
          this.$nextTick(() => {
            this.videoPlay.src = ipUrl;
            this.videoPlay.title = "音频";
            this.videoPlay.artist = " ";
            this.showPlayer = true;
          });
        }
      });
    },
    search() {
      let id = this.value[this.value.length - 1];
      this.$api
        .filterData({
          labelId: id,
          pageNum: this.currentPage,
          pageSize: this.pageSize,
        })
        .then((res) => {
          this.tableData = res.data.list;
          this.totalSize = res.data.total;
        });
    },
    reset() {
      this.value = [];
      this.getList();
    },
    selectionchange(row) {
      this.selectId = row;
    },
    submit() {
      let arr = [];
      this.selectId.forEach((res) => {
        arr.push({ id: res.id });
      });
      if (this.selectId.length == 0) {
        this.$message({
          showClose: true,
          message: "请选择一条数据进行通过",
          type: "warning",
        });
        return;
      }

      this.$api.getInfo(arr).then((res) => {
        if (res.code == 200) {
          this.$message.closeAll();
          this.$message({
            showClose: true,
            message: "提交成功",
            type: "success",
          });
          this.currentPage = 1;
          this.getList();
        }
      });
    },
    goBack() {
      let arr = [];
      this.selectId.forEach((res) => {
        arr.push({ id: res.id });
      });
      if (this.selectId.length == 0) {
        this.$message({
          showClose: true,
          message: "请选择一条数据进行退回",
          type: "warning",
        });
        return;
      }
      // console.log(arr,'arr')
      // return false
      this.$api.getOut(arr).then((res) => {
        if (res.code == 200) {
          this.$message.closeAll();
          this.$message({
            showClose: true,
            message: "退回成功",
            type: "success",
          });
          this.currentPage = 1;
          this.getList();
        }
      });
    },
    closeMp4() {
      this.$nextTick(() => {
        this.video.url = "obj";
        this.playVideo = false;
      });
    },
    musicClose(flag) {
      let ipUrl = "obj";
      this.$nextTick(() => {
        this.videoPlay.src = ipUrl;
        this.videoPlay.title = "";
        this.videoPlay.artist = "";
        this.showPlayer = flag;
      });
    },
    goEdit(row) {
      this.$router.push({
        path: "/archiveInfo",
        query: {
          row: JSON.stringify(row),
        },
      });
    },
    refresh() {
      this.currentPage = 1;
      this.getList();
    },
    handleSizeChange(val) {
      this.pageSize = val;
      // console.log(`每页 ${val} 条`);
      this.getList();
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      // console.log(`当前页: ${val}`);
      this.getList();
    },
  },
};
</script>
<style scoped lang="scss">
.archivingManag {
  padding: 0 30px;
  overflow: hidden;
  .seach-content {
    margin-top: 20px;
  }
  /deep/.el-button--primary {
    margin-left: 10px;
  }
  .content {
    height: 520px;
  }
  .pright {
    margin-right: 10px;
  }
  .btn-continer {
    margin-top: 30px;
    margin-bottom: 20px;
    .btn-right {
      float: right;
    }
  }
  .Pagination {
    text-align: right;
    margin-top: 40px;
  }
}
</style>

